﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyWrite.API.Appicant.Command.Roles;
using B.S.DataBase.MyWrite.API.Appicant.Command.UserCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyProject.API.Controllers
{
    /// <summary>
    /// 用户管理--写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MessageController : ControllerBase
    {
        private readonly IMediator mediator;

        public MessageController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddUser(AddUserCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> DelUser(DelUserCommand request)
        {
            return mediator.Send(request);
        }


        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> UpdateUser(UpdateUserCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> AddRole(RoleCreateCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<object>> DelRole(RoleDelCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 修改角色
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        [HttpPost]
        public Task<APIResult<object>> RoleUpdate(RoleUpdateCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 批量添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<object>> UserRoleAddRanges(UserRoleCommand request, CancellationToken cancellationToken)
        { 
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量删除用户角色关系表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<string>> RemoveUserRole(RemoveUserRoleCommand request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 通过角色ID批量删除关系表
        /// </summary>
        [HttpPost]
        public async Task<APIResult<string>> UserRoleRemoveRange(RemoveRoleIdCommand request)
        {
            return await mediator.Send(request);
        }

    }
}
